package br.com.insight.consultoria.integracao.dao;

import java.util.List;

import org.springframework.dao.DataAccessException;

import br.com.insight.consultoria.entity.CursoExtraCurricular;
import br.com.insight.consultoria.entity.Usuario;
import br.com.insight.consultoria.erro.exception.InsightConstants;
import br.com.insight.consultoria.erro.exception.InsightDaoException;
import br.com.insight.consultoria.erro.exception.InsightException;
import br.com.insight.consultoria.erro.exception.SistemaException;
import br.com.insight.consultoria.integracao.dao.genericdao.GenericDAO;
import br.com.insight.consultoria.integracao.dao.interfacedao.CursoExtraCurricularDAO;

public class CursoExtraCurricularImpDAO extends GenericDAO implements CursoExtraCurricularDAO{
	
	@Override
	public void inserir(CursoExtraCurricular cursoExtraCurricular)
			throws InsightException {

		try{
			
			saveOrUpdateEntity(cursoExtraCurricular);
			
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}
		
	}
	
	@Override
	public void alterar(CursoExtraCurricular cursoExtraCurricular)
			throws InsightException {
		
		try{
			
			saveOrUpdateEntity(cursoExtraCurricular);
			
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}
	}
	
	@Override
	public void excluir(CursoExtraCurricular cursoExtraCurricular)
			throws InsightException {

		try{
			
			deleteEntity(cursoExtraCurricular);
			
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}
		
	}
	
	@Override
	public CursoExtraCurricular getCursoExtraCurricular(Long id)
			throws InsightException {
		
		CursoExtraCurricular curricular=null;
		
		try{
			
			curricular=(CursoExtraCurricular) getEntityById(CursoExtraCurricular.class, id);
			
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}

		return curricular;
	}
	
	@Override
	public List<CursoExtraCurricular> pesquisar(Usuario usuario)
			throws InsightException {
		
		List<CursoExtraCurricular> cursoExtraCurricular=null;
		
		try{
			
			cursoExtraCurricular=findFiltered(CursoExtraCurricular.class,"usuario", usuario);
			
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}
		
		return cursoExtraCurricular;
	}

}
